

import { forwardRef, useImperativeHandle, useRef, useState } from "react";
import { DevGrid, DevPopup } from "~/public/cpas-ui";
import { StatSampleParameter } from "../../../typing";
import { consts } from "../../../consts";
import { getCpasPrimaryColor } from "@/utils/pub";
import { expansionCoefficientColumns, expansionCoefficientDataSource } from "./ExpansionCoefficientService";

//风险系数表

export const  ExpansionCoefficientPopup = forwardRef((props: {
    statSampleParameter?: StatSampleParameter,
    setStatSampleParameter?: (value: StatSampleParameter) => void
}, ref) => {

    const [visible, setVisible] = useState<boolean>(false);
    const diaParams = useRef<any>();
    const dataGridRef = useRef<any>();

    // 自定义方法
    useImperativeHandle(ref, () => ({
        show: (params: any) => {
            diaParams.current = params;
            setVisible(true);
        }
    }))
    function onCancel() {
        setVisible(false)
        if (diaParams.current.setIsNeedPopup) {
            diaParams.current.setIsNeedPopup(false);
        }
    }

    return <>
        <DevPopup.Logic
            visible={visible}
            title='扩张系数表'
            width={500}
            height={520}
            onHiding={onCancel}
            onCancel={onCancel}
            toolbarDisplay={false}
        >{() => {//必须用函数返回

            const acceptableRiskText = props.statSampleParameter?.acceptableRisk;

            return (<>
                <div style={{ marginBottom: 10, color: getCpasPrimaryColor() }}>
                    注：当预计存在错报时，注册会计师可以从可容忍错报中减去预计错报的影响，并使用预计没有错报时确定样本规模的方法计算选样间距；预计错报的影响等于预计错报与适当的扩张系数的乘积。扩张系数如下表：
                </div>
                <DevGrid.RangeTap
                    ref={dataGridRef}
                    className='devHeadersCenter PaperDevSortableGrid advancedQueryDataGrid'
                    dataSource={expansionCoefficientDataSource}
                    height={310}
                    keyExpr="acceptableRisk"
                    isRemote={true}
                    showBorders={false}
                    showRowLines={true}
                    showColumnLines={true}
                    rowAlternationEnabled={true}
                    columns={expansionCoefficientColumns}
                    paging={{ enabled: false }}
                   // scrolling={{ showScrollbar: 'never' }}

                />
                <div style={{ display: 'flex', alignContent: 'left', marginTop: 10, color: getCpasPrimaryColor() }}>
                    <div >
                        可接受的风险水平: {acceptableRiskText ? `【${acceptableRiskText}】` : consts.curNoValue}
                        对应值: {props.statSampleParameter?.expansionCoefficient || consts.curNoValue}</div>
                </div>
            </>)
        }}
        </DevPopup.Logic >
    </>
});
